<?php
	$host="localhost"; // Host name
	$username="root"; // Mysql username
	$password=""; // Mysql password
	$db_name="JSU_Database"; // Database name

	// Connect to server and select database.
	$message = mysql_connect($host, $username, $password)or die("cannot connect");
	mysql_select_db($db_name)or die("cannot select DB: ".mysql_error());
	
	//check for valid input and differentiate between counselors and advisors
	$switch = 0;
	if (isset($_GET['time'])){
		$time=$_GET['time'];
		$switch = 1;
	}
	if (isset ($_GET['ajNo']))
		$ajNo=$_GET['ajNo'];
	if (isset ($_GET['totalTime']))
		$totalTime=$_GET['totalTime'];
	if (isset ($_GET['ajNo2']))
		$ajNo2=$_GET['ajNo2'];
		
	//add appointment
	if ($switch = 1){
		$result = mysql_query("update acad_timetable set `".$time."` = 'Occupied' WHERE AdvisorJNo = '$ajNo'", $message);
		if (!$result) die(mysql_error($message));
		else header("location:appointmentList.php");
	} else {
		$result = mysql_query("update acad_timetable set `".$totalTime."` = 'Occupied' WHERE AdvisorJNo = '$ajNo2'", $message);
		if (!$result) die(mysql_error($message));
		else header("location:appointmentList.php");
	}
?>